home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / SOURCES / WEVENT.C < prev    next >
C/C++ Source or Header  |  1992-03-25  |  3KB  |  150 lines

  1. /*
  2.  * MS-dependent event code
  3.  */
  4.  
  5. #include <InterViews\itable.h>
  6. #include <InterViews\event.h>
  7. #include <InterViews\interactor.h>
  8. #include <InterViews\X11\eventrep.h>
  9. #include <InterViews\X11\worldrep.h>
  10. #include <InterViews\canvas.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13.  
  14. Event::Event() {
  15.     rep = new EventRep;
  16. }
  17.  
  18. Event::~Event() {
  19.     delete rep;
  20. }
  21.  
  22. void Event::GetMotionInfo() {
  23.     MSG msg = rep->msg;
  24.  
  25.     eventType = MotionEvent;
  26.     timestamp = msg.time;
  27.     x = LOWORD(msg.lParam);
  28.     y = HIWORD(msg.lParam);
  29.     GetRootCoord(x, y);
  30.     GetKeyState(msg.wParam);
  31.     FindWorld((void*)msg.hwnd);
  32. }
  33.  
  34. void Event::GetButtonInfo(EventType t) {
  35.     MSG msg = rep->msg;
  36.  
  37.     eventType = t;
  38.     timestamp = msg.time;
  39.     x = LOWORD(msg.lParam);
  40.     y = HIWORD(msg.lParam);
  41.  
  42.     switch(msg.message) {
  43.     case WM_LBUTTONDOWN:
  44.     case WM_LBUTTONUP:
  45.         button = LEFTMOUSE;
  46.         break;
  47.     case WM_MBUTTONDOWN:
  48.     case WM_MBUTTONUP:
  49.         button = MIDDLEMOUSE;
  50.         break;
  51.     case WM_RBUTTONDOWN:
  52.     case WM_RBUTTONUP:
  53.         button = RIGHTMOUSE;
  54.         break;
  55.     };
  56.  
  57.     len = 0;
  58.     GetKeyState(msg.wParam);
  59.     GetRootCoord(x, y);
  60.     FindWorld((void*)msg.hwnd);
  61. }
  62.  
  63. void Event::GetKeyInfo() {
  64.     MSG msg = rep->msg;
  65.  
  66.     eventType = KeyEvent;
  67.     timestamp = msg.time;
  68.     x = msg.pt.x;
  69.     y = msg.pt.y;
  70.     GetRootCoord(x, y);
  71.     button = msg.wParam;
  72.     keystring = keydata;
  73.     if (isascii(msg.wParam)) {
  74.     keystring[0] = msg.wParam;
  75.     keystring[1] = '\0';
  76.     len = 1;
  77.     } else {
  78.     keystring[0] = '\0';
  79.     len = 0;
  80.     }
  81.     GetKeybState();
  82.     FindWorld((void*)msg.hwnd);
  83. }
  84.  
  85. /*
  86.  *   Als Eintrittspunkt wird die neue Position des Cursors verwendet. Dieser
  87.  *   entspricht sicherlich nicht dem tatsächlichen, da die Berechnung der
  88.  *   neuen Cursorposition im Intervall 0.1 Sekunden oder nach WM_MOUSEMOVE
  89.  *   Nachrichten erfolgt, und bei einer schnellen Mausbewegung die Schritt-
  90.  *   weite merklich größer wird.
  91.  */
  92.  
  93.  
  94. boolean Event::GetCrossingInfo(EventType t) {
  95.     MSG msg = rep->msg;
  96.     POINT p;
  97.  
  98.     eventType = t;
  99.     timestamp = msg.time;
  100.     p.x = msg.pt.x;
  101.     p.y = msg.pt.y;
  102.     ScreenToClient(msg.hwnd, &p);
  103.     x = p.x;
  104.     y = p.y;
  105.     wx = msg.pt.x;
  106.     wy = msg.pt.y;
  107.     GetKeybState();
  108.     FindWorld((void*)msg.hwnd);
  109.     return true;
  110. }
  111.  
  112. void Event::GetRootCoord(int x, int y) {
  113.     POINT p;
  114.     p.x = x;
  115.     p.y = y;
  116.     ClientToScreen(rep->msg.hwnd, (LPPOINT)&p);
  117.     wx = p.x;
  118.     wy = p.y;
  119. }
  120.  
  121. void Event::GetKeyState(WORD state) {
  122.     shift = (state & MK_SHIFT) != 0;
  123.     control = (state & MK_CONTROL) != 0;
  124.     leftmouse = (state & MK_LBUTTON) != 0;
  125.     middlemouse = (state & MK_MBUTTON) != 0;
  126.     rightmouse = (state & MK_RBUTTON) != 0;
  127.     meta = 0;
  128.     shiftlock = 0;
  129. }
  130.  
  131. void Event::GetKeybState () {
  132.     shift = 0;
  133.     control = 0;
  134.     leftmouse = 0;
  135.     middlemouse = 0;
  136.     rightmouse = 0;
  137.     meta = 0;
  138.     shiftlock = 0;
  139. }
  140.  
  141. void Event::FindWorld(void* hwnd) {
  142.     Interactor* i;
  143.  
  144.     if (_world->itable()->Find(i, hwnd)) {
  145.     w = i->GetWorld();
  146.     } else {
  147.     w = nil;
  148.     }
  149. }
  150.